import 'package:flutter/material.dart';
import 'package:flutter_easyloading/flutter_easyloading.dart';
import 'package:flutter_screenutil/flutter_screenutil.dart';
import 'package:zootix/util/zt_screen_adaper_util.dart';

/// loading工具
class ZtLoadingUtil {
  ZtLoadingUtil() {}
  init() {
    EasyLoading.instance
      ..errorWidget = Icon(
        Icons.error,
        color: Colors.red,
        size: ZtScreenAdaper.sp(40),
      )
      ..successWidget = Icon(
        Icons.done,
        color: Colors.green,
        size: ZtScreenAdaper.sp(40),
      )
      ..radius = ZtScreenAdaper.sp(10)
      ..maskType = EasyLoadingMaskType.black
      ..userInteractions = false
      ..displayDuration = const Duration(milliseconds: 1500)
      ..dismissOnTap = false
      ..fontSize = ScreenUtil().setSp(20);
  }

  static Future<void> show({String? status}) async {
    EasyLoading.instance.userInteractions = false;
    return EasyLoading.show(status: status ?? 'Loading...');
  }

  static Future<void> showError(String? status) async {
    EasyLoading.instance.userInteractions = false;
    return EasyLoading.showError(status ?? 'Loading...');
  }

  static void toast(String text) {
    EasyLoading.showToast(text);
  }

  static Future<void> dismiss() async {
    EasyLoading.instance.userInteractions = true;
    return EasyLoading.dismiss();
  }
}
